package wat.clientapp.main;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;

/**
 *
 * @author P.B. & L.G. & K.K.
 */
public class Parameters {

    private static final String WSDL_URL = "erp.ws.login.wsdl.url";
    private static final String NAMESPACE = "erp.ws.login.wsdl.namespace";
    private static final String SERVICE_NAME = "erp.ws.login.wsdl.service";
    private static final String CP_DIR = "erp.classpath.dir";
    private static Parameters instance;
    private Properties properties;

    private Parameters() {
        try {
            properties = new Properties();
            InputStream is = new FileInputStream(new File("erp-client.properties"));
            properties.load(is);
        } catch (IOException ioe) {
            Logger.getLogger(Parameters.class.getName()).log(Level.SEVERE, "Blad podczas otwierania pliku erp-client.properties - zostana uzyte ustawienia domyslne", ioe);
            properties.setProperty(WSDL_URL, "http://localhost:8080/ErpLoginModule/LoginService?wsdl");
            properties.setProperty(NAMESPACE, "http://login.ws.erp.wat.edu.pl/");
            properties.setProperty(SERVICE_NAME, "LoginService");
            properties.setProperty(CP_DIR, "./build/classes/");
        }
    }

    public static Parameters getInstance() {
        if (instance == null) {
            instance = new Parameters();
        }
        return instance;
    }

    // =================== logowanie =============================
    public URL getLoginWsdlUrl() {
        try {
            return new URL(properties.getProperty(WSDL_URL));
        } catch (MalformedURLException ex) {
            Logger.getLogger(Parameters.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public QName getLoginQName() {
        return new QName(properties.getProperty(NAMESPACE), properties.getProperty(SERVICE_NAME));
    }
    
    // =================== ladowanie klas =============================
    public String getClasspathDir() {
        return properties.getProperty(CP_DIR);
    }
    
    // =================== administracja =============================
    
    
}
